const app = getApp();
Page({
  data: {

  },
  onLoad: function(options) {

  },
  onShow: function() {

  },
  onPullDownRefresh: function() {

  },
  inputUserInfoFinished: function(e) {
    var realName = e.detail.value.realName;
    var nickName = e.detail.value.nickName;
    var school = e.detail.value.school;
    var department = e.detail.value.department;
    var stuNo = e.detail.value.stuNo;
    var sex = e.detail.value.sex;
    var description = e.detail.value.description;
    var umbrellaType = e.detail.value.umbrellaType;
    if (realName == '' || nickName == '' ||
      school == '' || department == '' ||
      stuNo == '' || sex == '' || umbrellaType == '') {
      wx.showModal({
        title: '信息不完整',
        content: '请认真填写详细信息'
      });
    } else {
      wx.showLoading({
        title: '请稍后',
      });
      wx.request({
        url: 'http://' + app.globalData.host + '/save/user/info',
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
        },
        method: 'POST',
        data: {
          realName: e.detail.value.realName,
          nickName: e.detail.value.nickName,
          school: e.detail.value.school,
          department: e.detail.value.department,
          stuNo: e.detail.value.stuNo,
          sex: e.detail.value.sex,
          description: e.detail.value.description,
          umbrellaType: e.detail.value.umbrellaType,
          phone: app.globalData.phone
        },
        success: function(res) {
          if (res.data.code == 1) {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 1500
            });
            wx.hideLoading();
            app.globalData.sessionId = null;
            app.globalData.phone = null;
            // 去登录
            wx.redirectTo({
              url: '/pages/user/login/login',
            });
          } else {
            wx.showToast({
              title: '保存失败',
              icon: 'none',
              duration: 1500
            });
            wx.hideLoading();
          }
        },
        fail: function() {
          wx.showToast({
            title: '保存失败',
            icon: 'none',
            duration: 1500
          });
          wx.hideLoading();
        }
      });
    }
  }
})